<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\api\controller;


use app\api\lists\OrderLists;
use app\api\logic\IndexLogic;
use think\response\Json;


/**
 * index
 * Class IndexController
 * @package app\api\controller
 */
class IndexController extends BaseApiController
{


    public array $notNeedLogin = ['index', 'config', 'policy', 'decorate','getPrice','orderLists'];
    public function index()
    {
        $result = IndexLogic::getIndexData();
        return $this->data($result);
    }


    /**
     * @notes 全局配置
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author 段誉
     * @date 2022/9/21 19:41
     */
    public function config()
    {
        $result = IndexLogic::getConfigData();
        return $this->data($result);
    }

    /**
     * @notes 政策协议
     * @return Json
     * @author 段誉
     * @date 2022/9/20 20:00
     */
    public function policy()
    {
        $type = $this->request->get('type/s', '');
        $result = IndexLogic::getPolicyByType($type);
        return $this->data($result);
    }


    /**
     * @notes 装修信息
     * @return Json
     * @author 段誉
     * @date 2022/9/21 18:37
     */
    public function decorate()
    {
        $id = $this->request->get('id/d');
        $result = IndexLogic::getDecorate($id);
        return $this->data($result);
    }
    /**
     * 订单列表
     * @return Json
     */
    public function orderLists()
    {
        return $this->dataLists(new OrderLists());
    }

    /**
     * 创建订单
     * @return Json|void
     */
    public function orderCreate()
    {
        $content = $this->request->param("content");
        if (!$content) return $this->fail("请完善信息");
        $res = IndexLogic::orderCreate($this->userId, $content);
        if ($res === false) {
            return $this->fail(IndexLogic::getError());
        }
        return $this->data($res);
    }

    /**
     * 添加微信
     * @return Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWechat()
    {
        $res= IndexLogic::getWechat($this->userId);
        if ($res === false){
            return $this->fail(IndexLogic::getError());
        }
        return $this->data(["wechat"=>$res]);
    }

    public function getPrice()
    {
        return $this->data(["price"=> IndexLogic::getPrice()]);
    }

    public function orderDetail()
    {
        $pay_id =$this->request->param("pay_id");
        if (!$pay_id) return $this->fail("请输入订单id");
        $res = IndexLogic::orderDetail($pay_id);
        if (!$res)  return $this->fail(IndexLogic::getError());
        return $this->data($res);

    }

}